# -*-coding:utf-8-*-
import pandas as pd

df1 = pd.DataFrame([['m1', 110, 105],
                    ['m2', 105, 88],
                    ['m3', 92, 97],
                    ['m5', 109, 75]], columns=['name', 'math', 'english'])
df2 = pd.DataFrame([['m1', 110, 105],
                    ['m2', 105, 88],
                    ['m4', 87, 120],
                    ['m6', 110, 114]], columns=['name', 'math', 'english'])

"""1. 求两者的交集（列一样时即为求两者完全相同的行）
>>> df_intersected
  name  math  english
0   m1   110      105
1   m2   105       88
>>> df_intersected2
  name_x  math  english_x name_y  english_y
0     m1   110        105     m1        105
1     m1   110        105     m6        114
2     m2   105         88     m2         88
"""
df_intersected = pd.merge(df1, df2, how='inner')  # 求两者共有的列上数据相同的行
df_intersected2 = pd.merge(df1, df2, how='inner', on='math')  # 求两者特定的列上数据相同的行

"""1. 求两者的差集
>>> df_diff1
  name  math  english
2   m3    92       97
3   m5   109       75
>>> df_diff2
  name  math  english
2   m4    87      120
3   m6   110      114
"""
df_diff1 = pd.concat([df1, df2, df2]).drop_duplicates(keep=False)  # df1-df2
df_diff2 = pd.concat([df2, df1, df1]).drop_duplicates(keep=False)  # df2-df1